/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    bool isPalindrome(ListNode* head) 
    {
        if(head == NULL || head -> next == NULL)
            return true;
        
        ListNode* p = head;
        
        vector<int> val;//将链表值放入数组
        while(p)
        {
            val.push_back(p -> val);
            p = p -> next;
        }
        
        int m = 0, n = val.size() - 1;
        
        while(m < n)
        {
            if(val[m] != val[n])
                return false;
            else
            {
                m++;
                n--;
            }
        }
        
        return true;
        
    }
};